<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" import="com.uft.model.entity.*,java.util.List"%>
<%@ page isELIgnored="false"%>
<script>
$( ".column" ).sortable({
    connectWith: ".column",
    handle: ".portlet-header",
    cancel: ".portlet-toggle",
    placeholder: "portlet-placeholder ui-corner-all"
  });
$( ".portlet" )
.addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
  .addClass( "ui-widget-header ui-corner-all" )
  .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>");
$( ".portlet-toggle" ).click(function() {
		 var icon = $( this );
		 icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" );
	icon.closest( ".portlet" ).find( ".portlet-content" ).toggle();
});
$( "#serverSettingSaveBtn_<c:out value="${serverSetting.id}"/>").button({
	icons: {
           primary: "ui-icon-disk"
         }
});
$( "#serverSettingTestConnectionBtn_<c:out value="${serverSetting.id}"/>").button({
	icons: {
           primary: "ui-icon-lightbulb"
         }
}).click(function(event){
	event.preventDefault();
	var username=$('#sshUsername_<c:out value="${serverSetting.id}"/>').val();
	var password=$('#sshPassword_<c:out value="${serverSetting.id}"/>').val();
	$.ajax({
    	  type: "POST",
    	  dataType: 'json',
    	  global: false,
    	  url: "testServerSSHConnection.htm",
    	  data: {
    		hostname: '<c:out value="${server.serverHostname}"/>', 
    		username: username,
    		password: password
    	  },
    	  success: function(result){
    		  if (result.Result == "OK") {
    			  generateDiag("center","success", "Connection Tested. OK!");
    		  }else{
    			  generateDiag("center","error", result.Message);
    		  }
    	  },
    	  error: function () {
    		  generateDiag("center","error", "Error Connecting Server");
    	  },
        	beforeSend: function(){
				waitingDialog({title: "Test Connection", message: "Testing Connections..."});
			},
			complete: function(){
				closeWaitingDialog();
			}
    	  
    	});
	
});
$('#serverSettings_<c:out value="${serverSetting.id}"/>').submit(function() { 
	var options = {
			url: "updateServerSetting.htm",
			type: "POST",
		  	dataType: 'json',
		  	beforeSubmit: function(){
				$("#serverSettingSaveBtn_<c:out value="${serverSetting.id}"/>").attr("disabled", "disabled");
			},
			success: function(data){
				if(data.Result == "OK"){
					generateDiag("center","success", "Successfully Saved!");
					$("#serverSettingSaveBtn_<c:out value="${serverSetting.id}"/>").removeAttr("disabled")
				}else{
					generateDiag("center","error", "Error Saving");
				}
			}
			
	}
	$(this).ajaxSubmit(options);
	return false;
	
	
});
</script>
<form id="serverSettings_<c:out value="${serverSetting.id}"/>" action="updateServerSetting.htm" method="post">
<table width="100%">
	<tr><td colspan="2" align="right"><button  type="submit" name="submit" id="serverSettingSaveBtn_<c:out value="${serverSetting.id}"/>" >Save</button></td></tr>
</table>
<div class="column">
<div class="portlet" id="Information">
	<div class="portlet-header">
		Server SSH Connection
	</div>
	<div class="portlet-content">
			<input type="hidden" id="id_<c:out value="${serverSetting.id}"/>" name="id" value="<c:out value="${serverSetting.id}"/>" />
			<table width="100%">
				<tr>
					<td>SSH Enabled</td>
					<td><input type="checkbox" name="sshEnabled"  id="sshEnabled_<c:out value="${serverSetting.id}"/>" <c:if test="${serverSetting.sshEnabled}">checked</c:if> class="checkbox ui-widget-content ui-corner-all"/></td>
						
				</tr>
				<tr>
					<td>SSH Username:</td>
					<td><input type="text" name="sshUsername" id="sshUsername_<c:out value="${serverSetting.id}"/>" value="<c:out value="${serverSetting.sshUsername}"/>" class="text ui-widget-content ui-corner-all" /></td>
				</tr>
				<tr>
					<td>SSH Password:</td>
					<td><input type="password" name="sshPassword" id="sshPassword_<c:out value="${serverSetting.id}"/>" value="<c:out value="${serverSetting.sshPassword}"/>" class="text ui-widget-content ui-corner-all" /></td>
				</tr>
				<tr>
					<td colspan=2 align="right">
						<button id="serverSettingTestConnectionBtn_<c:out value="${serverSetting.id}"/>">Test Connection</button>
					</td>
				</tr>
			</table>
		
	</div>
</div>
</form>
